package main

type ListNode struct {
	Val  int
	Next *ListNode
}

/**
 *
 * @param head ListNode类
 * @return bool布尔型
 */
func hasCycle(head *ListNode) bool {
	// write code here
	ptr1, ptr2 := head, head
	for {
		if ptr2 == nil || ptr2.Next == nil {
			return false
		}
		ptr2 = ptr2.Next.Next
		ptr1 = ptr1.Next
		if ptr1 == ptr2 {
			break
		}
	}
	return true
}
